package pe.edu.claretiano.admisionmatricula.admision.daoimpl;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;

import pe.edu.claretiano.admisionmatricula.admision.dao.PersonaDao;
import pe.edu.claretiano.admisionmatricula.bean.Persona;
import pe.edu.claretiano.admisionmatricula.factory.MyBatisConnectionFactory;

public class PersonaDaoImpl implements PersonaDao {
	
	private final static Logger logPersonaDaoImpl = Logger
			.getLogger(PersonaDaoImpl.class);
	
	private SqlSessionFactory sqlSessionFactory;
	
	public PersonaDaoImpl(){
		sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
	}

	@Override
	public Integer insertarPersona(Persona objPersona) {
		
		SqlSession session = sqlSessionFactory.openSession();
		Integer resultado=0;
		try {
			resultado=session.insert("Persona.insertarPersona", objPersona);			
			session.commit();			
		} catch (Exception ex) {
			logPersonaDaoImpl.error(ex.getMessage());				
			session.rollback();
		} finally {
			session.close();
		}
		return resultado;
	}

}
